package com.dronff.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.*;
import org.apache.log4j.Logger;

public class TangRPCProviderChannelInitializer extends ChannelInitializer<NioSocketChannel> {
    static final Logger logger = Logger.getLogger(TangRPCProviderChannelInitializer.class);

    @Override
    protected void initChannel(NioSocketChannel nioSocketChannels) throws Exception {
        logger.debug("有一个新的连接");
        nioSocketChannels
                .pipeline()
                .addLast(
                        new ProtocolSelectHandler()
                )
                .addLast(
                        new TangProtocolInvokerInboundHandler()
                )
//                .addLast(
//                        new HttpServerCodec()
//                )
//                .addLast(
//                        "httpAggregator",new HttpObjectAggregator(512*1024)
//                )
//                .addLast(
//                        new SimpleChannelInboundHandler<FullHttpRequest>() {
//                            @Override
//                            protected void channelRead0(ChannelHandlerContext channelHandlerContext, FullHttpRequest fullHttpRequest) throws Exception {
//                            }
//                        }
//                )
                .addLast(
                        new TangProtocolInvokerOutboundHandler()
                );
    }
}
